home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 413 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.4 KB

  1. Path: news.rmii.com!usenet
  2. From: jcoffin@rmii.com (Jerry Coffin)
  3. Newsgroups: comp.std.c
  4. Subject: Re: fflush: ANSI C v. POSIX.1
  5. Date: Fri, 16 Feb 1996 19:17:04 GMT
  6. Organization: TAEUS
  7. Message-ID: <4g2got$2s2@natasha.rmii.com>
  8. References: <4frf81$gmn@clark.edu>
  9. NNTP-Posting-Host: slip22160.rmii.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. cowen@clark.edu (James M. Cowen) wrote:
  13.  
  14. [ ... ] 
  15. >In short, I'm confused, can someone clarify how one would use fflush()
  16. >in a portable fashion ... no that's not what I want to ask.  Don't use
  17. >fflush() on a read/update stream,  that seems obvious given ANSI C, but 
  18. >it "works" on POSIX.1 systems, but POSIX.1 indicates it accepts the
  19. >ANSI C standard, but ... I hope you get the drift of my question.
  20.  
  21. >In passing, I'm teaching a class using W. Richard Stevens book, "Advanced 
  22. >Programming in a Unix Environment", and was unable to advance a satisfactory
  23. >explanation of fflush() with respect to ANSI C and POSIX.1.  Indeed, my
  24. >response, "interesting" was not only unsatisfactory to my students, it
  25. >was inappropriate. 
  26.  
  27. Everything here sounds perfectly reasonable to me.  POSIX.1 includes the
  28. ISO standard for C, therefore everything that's defined in the C
  29. standard is also defined in POSIX.  However, POSIX also defines quite a
  30. bit more, that is NOT defined in the C standard.  In many cases the new
  31. definitions are embodied in functions that are not defined in the C
  32. standard at all, and typically using headers that are not defined in the
  33. C standard either.  
  34.  
  35. However, some of the behavior specified by POSIX involves defining
  36. behavior of functions that are in the C standard, but which are more
  37. restrictive of the functions (and therefore less restrictive on calling
  38. code) than the C standard.  For instance, the C standard mandates the
  39. presence of `errno' and specifies its purpose, but has only a minimal
  40. definition of how its value may be affected by standard functions.
  41. POSIX is more restrictive in specifying considerably more about what
  42. functions will set errno to particular values and under what
  43. circumstances they will do so.
  44.  
  45. Likewise, with fflush, the C standard simply doesn't define the results
  46. unless it's applied to a stream opened for writing, or opened for update
  47. and for which the last operation was a write.  POSIX apparently
  48. restricts the function further, by saying that it must provide a defined
  49. result when applied to a stream opened for reading, or from which
  50. reading has been done.
  51.  
  52.